package com.iman.manjusri.service.impl;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.inject.Inject;

import org.springframework.stereotype.Service;

import com.iman.common.support.Page;
import com.iman.manjusri.mappers.HomeMapper;
import com.iman.manjusri.service.HomeHyService;
import com.iman.manjusri.vo.HomeVo;

@Service
public class HomeHyServiceImpl implements HomeHyService {
	@Inject
	private HomeMapper homeHyMapper;

	@Override
	public Page<HomeVo> getHome(int type, int ps, int pn) {
		
		Map<String, Object> params = new HashMap<String, Object>();
		
		Page<HomeVo> pages = new Page<HomeVo>();
		int totalCount = 0;
		List<HomeVo> result = null;
		if (type == 1) {
			params.put("offset", (pn - 1) * ps);
			params.put("limit", ps);
			result = homeHyMapper.getHomeHy(params);
			totalCount = homeHyMapper.getHomeHy(null).size();
			pages.setData(result);
			pages.setPageSize(ps);
			pages.setStart((pn - 1) * ps);
			pages.setTotalCount(totalCount);
		} else if(type == 2){
			params.put("offset", (pn - 1) * ps);
			params.put("limit", ps);
			result = homeHyMapper.getTeacher(params);
			totalCount = homeHyMapper.getTeacher(null).size();
			pages.setData(result);
			pages.setPageSize(ps);
			pages.setStart((pn - 1) * ps);
			pages.setTotalCount(totalCount);
		}else if(type == 3){
			params.put("offset", 1);
			params.put("limit", 36);
			result = homeHyMapper.getLatestHy(params);			
			pages.setData(result);		
		}else if(type == 4){
			params.put("offset", (pn - 1) * ps);
			params.put("limit", ps);
			result = homeHyMapper.getStudent(params);
			totalCount = homeHyMapper.getStudent(null).size();
			pages.setData(result);
			pages.setPageSize(ps);
			pages.setStart((pn - 1) * ps);
			pages.setTotalCount(totalCount);	
		}
		return pages;
	}

}
